package com.asa.fushu;

import java.util.ArrayList;
import java.util.List;

import com.asa.fushu.bean.Fushu;

public class MathUtilsFuShu {
	
	
	
	
	/**
	 * 函数零点
	 * @param startw 实部分
	 * @param endw 实部分
	 * @param starth
	 * @param endh
	 * @param buchang
	 * @param jindu
	 * @param function
	 * @return
	 */
	public static List<Fushu> get0jie(double startw,double endw,double starth,double endh,double buchang,double jindu,RFunction function) {
		
		
		List<Fushu> fs = new ArrayList<>();
		
		for (double i = startw; i <= endw; i+=buchang) {
			
			for (double j = starth; j <= endh; j+=buchang) {
				
				Fushu fushu = new Fushu(i,j);
				Fushu e = function.hanshu(fushu);
				
				double length = e.length();
//				System.out.println(length);
				if(length<jindu) {
//					System.out.println(fushu);
					fs.add(fushu);
				}
				
				
			}
			
		}
		return fs;
		
	}
	
	
	
	
	/**
	 * 函数值
	 * @param startw 实部分
	 * @param endw 实部分
	 * @param starth
	 * @param endh
	 * @param buchang
	 * @param jindu
	 * @param function
	 * @return
	 */
	public static List<Fushu> getY(double startw,double endw,double starth,double endh,double buchang,RFunction function) {
		
		
		List<Fushu> fs = new ArrayList<>();
		
		for (double i = startw; i <= endw; i+=buchang) {
			
			for (double j = starth; j <= endh; j+=buchang) {
				
				Fushu e = new Fushu(i,j);
				e = function.hanshu(e);
				
				fs.add(e);
			}
			
		}
		return fs;
		
	}
	
	
	
	
	
	
	
	
	/**
	 * 韦达定理
	 * 一元二次方程的求根公式
	 * 传入的参数都是实数，应该可以传复数，但我不知道怎么传，其实事有思路的（用欧拉公式转换复数），但感觉太复杂了
	 */
	public static Fushu[] WD(double a,double b,double c) {
		
		double de = (b*b-4*a*c)/(2*a);
		
		
		double da = -b/(2*a);
		
		
		if (de<0) {
			
			double pow = Math.pow(-de, 0.5);
			

			
			Fushu fushu1 = new Fushu(da,-pow);
			Fushu fushu2 = new Fushu(da,+pow);

			Fushu[] fushus = new Fushu[2];
			fushus[0] = fushu1;
			fushus[1] = fushu2;
			
			return fushus;

		}
		
		double pow = Math.pow(de, 0.5);
		

		
		Fushu fushu1 = new Fushu(da-pow,0);
		Fushu fushu2 = new Fushu(da+pow,0);

		Fushu[] fushus = new Fushu[2];
		fushus[0] = fushu1;
		fushus[1] = fushu2;

		return fushus;
	}
	
	
	
	
	
	
	

}
